<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@page import="com.qifan.alb2b.domain.CountryInfoDomain"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <title>易能旅游网站</title>
	<%@ include file="/pages/common/common_f.jsp" %>
	<link rel="stylesheet" type="text/css" href="${ctx}/css/back.css" />
	<style type="text/css">
		a:hover{
			text-decoration: none;
		}
		
		a.ordera:hover{
			text-decoration: underline;
			color:#15428B;
		}
	</style>
	<script type="text/javascript">
		$(function(){	
			$('#gridTable').datagrid({
				title:'订单列表', //标题
				method:'post',
				iconCls:'icon-edit', //图标
				singleSelect:false, //多选
				height:360, //高度
				fitColumns: false, //自动调整各列，用了这个属性，下面各列的宽度值就只是一个比例。
				striped: true, //奇偶行颜色不同
				collapsible:true,//可折叠
				url:"${ctx}/order/query.usr", //数据来源
				sortName: 'orderId', //排序的列
				sortOrder: 'desc', //倒序
				remoteSort: true, //服务器端排序
				idField:'orderId', //主键字段
				queryParams:{}, //查询条件
				pagination:true, //显示分页
				rownumbers:true, //显示行号
				frozenColumns:[[
					{field:'ck',checkbox:true,width:2}, //显示复选框
					{field:'orderId',title:'订单编号',width:150,
						formatter:function(value,row,index){
							return '<a href="${ctx}/order/queryOrderDetail.usr?orderId='+row.orderId+'" target="_blank" class="ordera">'+row.orderId+'<a>';
						}	
					}
				]],
				columns:[[
					{field:'day',title:'几天',width:45,sortable:true},
					{field:'night',title:'几夜',width:45},
					{field:'goCityCn',title:'启程城市',width:60},
					{field:'goTime',title:'启程时间',width:80},
					{field:'backTime',title:'返回时间',width:80},
					{field:'groupType',title:'团队类型',width:65,
						formatter:function(value,row,index){
							switch(row.groupType){
								case ${constant.GROUP_TYPE_SIX}:
									return '1-6人团';
									break;
								case ${constant.GROUP_TYPE_SEVEN}:
									return '7-38人团';
									break;
								default:
									return '未知';
									break;
							}
						}	
					},
					{field:'totalCount',title:'总人数',width:45,sortable:true},
					{field:'orderStatus',title:'订单状态',width:65,sortable:true,
						formatter:function(value,row,index){
							switch(row.orderStatus){
								case ${constant.ORDER_STATUS_NOPAY}:
									return '未付款';
									break;
								case ${constant.ORDER_STATUS_PAYED}:
									return '已付款';
									break;
								case ${constant.ORDER_STATUS_OK}:
									return '已确认';
									break;
								case ${constant.ORDER_STATUS_CANCEL}:
									return '已取消';
									break
								default:
									return '未知';
									break;
							}
						}
					},
					{field:'orderTotalAmount',title:'总金额',width:55,sortable:true},
					{field:'createTime',title:'创建时间',width:140,sortable:true},
					{field:'payTime',title:'付款期限',width:140,sortable:true}
				]],
				toolbar:[
					{
						text:'付款订单',
						iconCls:'icon-ok',
						handler:function(){
							updateStatus(${constant.ORDER_STATUS_PAYED});
						}
					},'-',{
						text:'取消订单',
						iconCls:'icon-close',
						handler:function(){
							updateStatus(${constant.ORDER_STATUS_CANCEL});
						}
					},'-'
				],
				onLoadSuccess:function(){
					$('#gridTable').datagrid('clearSelections'); //一定要加上这一句，要不然datagrid会记住之前的选择状态，删除时会出问题
				}
			});	
		});
		
		/** 更新订单状态 */
		function updateStatus(status){
			var rows = $('#gridTable').datagrid('getSelections');//json：[{},{}]
		
			if(rows.length==0){
				$.messager.alert('提示','请选择你要更新的记录','info');
				return;
			}
			if(rows.length > 1){
				$.messager.alert('提示','只能选择一条记录进行更新','info');
				return;
			}
			var param={
				orderId:rows[0].orderId,	
				orderStatus:status
			};				
			$.post('${ctx}/order/updateStatus.usr',param,function(data){
	        	if(data.success){//操作成功
					$.messager.alert('提示','操作成功','info');
	        		$('#gridTable').datagrid('reload');//刷新数据
				}else{
					$.messager.alert('提示',data.msg,'warning');	
				}
	        });
		}
		
		 /** 表格查询 */
		function searchOrder(){
			var fields =$('#queryForm').serializeArray(); //自动序列化表单元素为JSON对象数据格式如下
		
			var params={};
			$.each( fields, function(i, field){//设置查询参数
				params[field.name] = field.value; 
			});
			$('#gridTable').datagrid('reload',params); //设置好查询参数 reload 一下就可以了
		}
		
		/** 清空查询条件 */
		function clearForm(){
			$('#queryForm').form('clear');
		}
	</script>	
  </head>
  <body style="margin:0;padding:0;height:100%;overflow:scroll;background:#F2FBFF">
  	<div class="main">
		<jsp:include page="/pages/front/inc/header.jsp"></jsp:include><!-- 顶部导航 -->
		<div class="info">
			<span class="location"><span style="font-weight: bold;">位置：</span>首页>用户中心>订单管理</span>
			<span class="user"><jsp:include page="/pages/front/inc/login_info.jsp"/></span>
		</div>
		<div class="content">
			<div class="left">
				<jsp:include page="/pages/front/user/left_model.jsp"/><!-- 左侧操作 -->
			</div>
			<div class="right" id="right">
				<form id="queryForm" class="qform" style="margin:5px 5px 0px 5px;border: 1px solid #92B7D0;border-bottom: 0px;">
					<table class="qtable" width="100%">
						<tr>
							<td class="qtd">订&nbsp;单&nbsp;号：<input class="txt" name="orderId" style="width: 100px;"></td>
							<td class="qtd">订单状态：
								<select class="easyui-combobox" name="orderStatus" panelHeight="auto" style="width:100px;" editable="false">
									<option value="-1">请选择</option>
									<option value="${constant.ORDER_STATUS_NOPAY}">未付款</option>
									<option value="${constant.ORDER_STATUS_PAYED}">已付款</option>
									<option value="${constant.ORDER_STATUS_OK}">已确认</option>
									<option value="${constant.ORDER_STATUS_CANCEL}">已取消</option>
								</select>
							</td>
							<td class="qtd">团队类型：
								<select class="easyui-combobox" name="groupType" panelHeight="auto" style="width:100px;" editable="false">
									<option value="-1">请选择</option>
									<option value="${constant.GROUP_TYPE_SIX}">1-6人团</option>
									<option value="${constant.GROUP_TYPE_SEVEN}">7-38人团</option>
								</select>
							</td>
							<td class="qtd" align="center"><a style="text-decoration: none;" onclick="clearForm();" class="easyui-linkbutton" iconCls="icon-no">清空</a></td>
						</tr>
						<tr>
							<td class="qtd" colspan="3">创建时间：<input class="txt" name="createBeginTime" style="width: 100px;" onfocus="WdatePicker();">--
							<input class="txt" name="createEndTime" style="width: 100px;" onfocus="WdatePicker();">
							</td>
							<td class="qtd" align="center"><a style="text-decoration: none;" onclick="searchOrder();" class="easyui-linkbutton" iconCls="icon-search">查询</a></td>
						</tr>
					</table>
				</form>
				<div class="griddiv">
					<table id="gridTable"></table>
				</div>			
			</div><!-- end right -->
			<div class="vertical-border" style="height: 500px;"></div><!-- center border-line -->
		</div><!-- end content -->
	</div><!-- end main -->
	

</body>

</html>
